package com.yun.baymax.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.yun.baymax.R;
import com.yun.baymax.activity.ShowImageActivity;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/6/12.
 */

public class TrendsDetailAdapter extends RecyclerView.Adapter<TrendsDetailAdapter.MyHolder> {
    Context context;
    int type;
    List<String> datas = new ArrayList<>();
    private LayoutInflater inflater;

    public TrendsDetailAdapter(Context context, List<String> datas, int type) {
        this.context = context;
        this.datas = datas;
        this.type = type;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public MyHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(type == 0 ? R.layout.item_trends_detail : R.layout.item_trends_inner, parent, false);
        MyHolder myHolder = new MyHolder(view);
        return myHolder;
    }

    @Override
    public void onBindViewHolder(MyHolder holder, final int position) {
        if (!TextUtils.isEmpty(datas.get(position)))
            Glide.with(context).load(datas.get(position)).into(holder.ivPic);

        holder.ivPic.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                context.startActivity(new Intent(context, ShowImageActivity.class).putExtra("uri", datas.get(position)));
            }
        });
    }

    @Override
    public int getItemCount() {
        return datas == null ? 0 : datas.size();
    }

    public class MyHolder extends RecyclerView.ViewHolder {
        private ImageView ivPic;

        public MyHolder(View itemView) {
            super(itemView);
            ivPic = (ImageView) itemView.findViewById(R.id.iv_pic);
        }
    }
}